#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>

int main()
{
    umask(0);//需要root权限
    //由于操作系统默认打开stdin，stdout和stderr，所以后面打开的文件下标是从三开始的
    int fp1 = open("log1.txt",O_TRUNC|O_WRONLY|O_CREAT,0666);
    const char* msg = "hello Linux";
    write(fp1,msg,strlen(msg));
    //int fp2 = open("log2.txt",O_TRUNC|O_WRONLY|O_CREAT,0666);
    //int fp3 = open("log3.txt",O_TRUNC|O_WRONLY|O_CREAT,0666);
    //int fp4 = open("log4.txt",O_TRUNC|O_WRONLY|O_CREAT,0666);
    ////printf("%d\n",getumask());
    //printf("%d\n",fp1);
    //printf("%d\n",fp2);
    //printf("%d\n",fp3);
    //printf("%d\n",fp4);
    close(fp1);
    //printf("%d\n",stdin->_fileno);
    //printf("%d\n",stdout->_fileno);
    //printf("%d\n",stderr->_fileno);

    //printf("pid:%d\n",getpid());
    ////chdir("/home/yg");
    ////w是清空再写入，a是直接在原有的后面添加。
    //FILE* fp = fopen("log.txt","w");
    //const char* inp = "Hello Linux";
    //fwrite(inp,strlen(inp),fp);
    ////fprintf(fp,"%s\n",inp);
    //fclose(fp);
    //return 0;
}
